package drds.common.db.xml_mapping.script.xml_tags;

import java.util.List;


public class Choose implements DynamicNode {
  private final List<DynamicNode> ifNodeList;
  private final DynamicNode defaultNode;

  public Choose(List<DynamicNode> ifNodeList, DynamicNode defaultNode) {
    this.ifNodeList = ifNodeList;
    this.defaultNode = defaultNode;
  }

  @Override
  public boolean apply(DynamicNodeContext dynamicNodeContext) {
    for (DynamicNode ifNode : ifNodeList) {
      if (ifNode.apply(dynamicNodeContext)) {
        return true;
      }
    }
    if (defaultNode != null) {
      defaultNode.apply(dynamicNodeContext);
      return true;
    }
    return false;
  }
}
